#ifndef _TREE
#define _TREE


#include <d3d10.h>
#include <d3dx10.h>
#include <string>
#include "treeCuda.h"
#include "l_systems.h"
#include "tree_helpers.h"
#include "vertex.h"
#include <stack>
#include <vector>
#include "drawableObject.h"



const float DEFAULT_ANGLE=0.3f;

class Tree
{
private:

	int						m_size;

	int						m_leafCount;				//number of leafs per branch
	int						m_walls;	
	
	ID3D10Device*			m_pd3dDevice;

	DrawableObject	* m_Leafs;
	DrawableObject	* m_Branches;

	
	LPD3DXMATRIXSTACK	    m_matrixStack;
	///list of branch structures
	std::vector<branch*>		m_BranchList;
	///list of branches with leafs
	std::vector<branch>		m_LeafList;

	void calculateThickness(std::vector<branch*> * b);	
	void rotateZ(float angle,D3DXMATRIX * w);
	void rotateX(float angle,D3DXMATRIX * w);
	void rotateY(float angle,D3DXMATRIX * w);
	void push(D3DXMATRIX * w);
	void pop(D3DXMATRIX * w);
	void addBranch(D3DXMATRIX*, float length, branch ** p);



public:


	Tree(ID3D10Device* d, int s);
	~Tree();
	HRESULT generateLSys(LSystem * system, int level, float length  );
	HRESULT generateCuda(int w, float r);
	HRESULT generateLeafsCUDA(int n, float size);
	

	void renderBranches();
	void renderLeafs();

	DrawableObject * GetBranches();
	DrawableObject * GetLeafs();


};

#endif